package practice1_100;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Practice781 {
    public int numRabbits(int[] answers) {
        int count=0;
        Map<Integer,Integer> map=new HashMap<>();
        Set<Integer> set=new HashSet<>();
        for (int i = 0; i < answers.length; i++) {
            if(answers[i]==0){
                count++;
                continue;
            }
            if(map.get(answers[i])==null||map.get(answers[i])==0){
                map.put(answers[i],answers[i] );
                //continue;
            }else if(map.get(answers[i])==1) {
                count+=answers[i]+1;
                map.put(answers[i],map.get(answers[i])-1 );
            }else {
                map.put(answers[i],map.get(answers[i])-1 );
            }


        }
        for (Integer j : map.keySet()) {
            if(map.get(j)!=0){
                count+=j+1;
            }
        }
        return count;
    }

    public static void main(String[] args) {
//        [0,0,1,1,1]
        //1,2,4,4,3,5,3,5,6,6,6,7,3,4,2,1,3,3,4,4,5,5
        int a=new Practice781().numRabbits(new int[]{3,3,3,3});
        System.out.println(a);
    }
}
